﻿using UnityEngine;
using System.Collections.Generic;

namespace KaoticSSB
{
	public class ParticleManager : MonoBehaviour 
	{
		// Use this for initialization
		void Start () 
		{
			
		}
		
		// Update is called once per frame
		void Update () 
		{
			for(int i = mParticleSystems.Count-1; i >=0; --i)
			{
				ParticleSystem system = mParticleSystems[i];
				if(system.IsAlive() == false)
				{
					mParticleSystems.Remove(system);
					Destroy(system.transform.root.gameObject);
				}
			}
		}

		public void CreateAnimatedSpriteParticleSystem(Transform particleSystem, Vector3 position, float rotation, float scale)
		{
			Transform transform = Instantiate(particleSystem, position, Quaternion.identity) as Transform;
			ParticleSystem system = transform.gameObject.GetComponentInChildren<ParticleSystem>();
			system.startSize = system.startSize * scale;
			system.startRotation = Mathf.Deg2Rad * rotation;
			system.renderer.sortingLayerName = "Effects";

			if(system != null)
			{
				mParticleSystems.Add(system);
			}
		}

		public float GetRotation(Vector3 start, Vector3 end, float degreeOffset)
		{
			float rotation = 0.0f;

			return rotation;
		}

		private List<ParticleSystem> mParticleSystems = new List<ParticleSystem>();
	}
}